-module(config). 

-compile(export_all).

    
get_tcp_listener() ->
    case application:get_env(tcp_listener) of
     {ok, false} -> throw(undefined);
    {ok, Tcp_listener} -> 
        try
            {_, Port} = lists:keyfind(port, 1, Tcp_listener),
            {_, Acceptor_num} = lists:keyfind(acceptor_num, 1, Tcp_listener),
            {_, Max_connections} = lists:keyfind(max_connections, 1, Tcp_listener),
            [Port, Acceptor_num, Max_connections]
        catch
             _:_ -> exit({bad_config, {server, {tcp_listener, config_error}}})
        end;
     undefined -> throw(undefined)
    end.

get_tcp_listener_ip() ->
    case application:get_env(tcp_listener_ip) of
     {ok, false} -> throw(undefined);
    {ok, Tcp_listener_ip} -> 
        try
            {_, Ip} = lists:keyfind(ip, 1, Tcp_listener_ip),
            [Ip]
        catch
             _:_ -> exit({bad_config, {server, {tcp_listener, config_error}}})
        end;
     undefined -> throw(undefined)
    end.

%% 获取 .config里的配置信息
get_log_level() ->
    case application:get_env(log_level) of
    {ok, Log_level} -> Log_level;
    _ -> 3
    end.

 %% 获取日志配置方式 
get_log_type() ->
    case application:get_env(log_ctrl) of
    {ok,Log_type} -> Log_type;
    _ -> 0
    end.
	
%%获取C Node 日志节点
get_log_node() ->
        case application:get_env(logger_no) of
    {ok,Logger_no} -> Logger_no;
     _ -> throw(undefined)
    end.	